
public class TranditionalThreadSynchronized {
	public static void main(String [] args) {
		final Businiss businiss = new Businiss();
	
		new Thread(new Runnable(){
			public void run() {
				for(int j=0;j<100;j++){
					try {
						Thread.sleep(200);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
//					businiss.print("abcdefg");
					businiss.print("abcdefg");
				}
			}
		}).start();
		
		new Thread(new Runnable(){
			public void run() {
				for(int j=0;j<100;j++){
					try {
						Thread.sleep(200);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
//					businiss.print("1234567");
					businiss.print3("1234567");
				}
			}
		}).start();
		
	}
	
	
	
}

class Businiss {
	
	public synchronized void print(String name) {
		for(int i=0;i<name.length();i++){
			System.out.print(name.charAt(i));
		}
		System.out.println();
	}
	
	public void print2(String name) {
		synchronized(Businiss.class){
			for(int i=0;i<name.length();i++){
				System.out.print(name.charAt(i));
			}
			System.out.println();
		}
	}
	//和print2比较同一个锁对象(Businiss.class)锁两个方法
	public static synchronized void print3(String name) {
		for(int i=0;i<name.length();i++){
			System.out.print(name.charAt(i));
		}
		System.out.println();
	}
	
}
